package org.dreamwork.jasmine2.web.client;

import java.util.regex.Matcher;

/**
 * Created by IntelliJ IDEA.
 * User: seth.yang
 * Date: 12-4-25
 * Time: 下午6:14
 */
public class SafariParser {
/*
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/534.53.11 (KHTML, like Gecko) Version/5.1.3 Safari/534.53.10
group[1]=534.53.11
group[2]=5.1.3

Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1
group[1]=533.21.1
group[2]=5.0.5

Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; zh-cn) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27
group[1]=533.20.25
group[2]=5.0.4
 */
    public static UserAgent parse (Matcher m) {
        UserAgent agent = new UserAgent (m.group (0));
        agent.setDevice (DeviceType.Computer);
        agent.setType (BrowserType.Safari);

        OperationSystem os = OSParser.parseOS (m.group (0));
        agent.setOs (os);

        Version version = new Version (m.group (1));
        RenderKernel kernel = new RenderKernel (RenderkernelType.AppleWebKit, version);
        agent.setKernel (kernel);

        version = new Version (m.group (2));
        agent.setVersion (version);

        return agent;
    }
}
